package ynu.edu.online_course.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ynu.edu.online_course.entity.Comment;
import ynu.edu.online_course.service.CommentService;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping
    public ResponseEntity<?> addComment(@RequestBody Comment comment) {
        commentService.addComment(comment);
        return ResponseEntity.ok("成功发布评论");
    }

    @DeleteMapping("/{id}/user")
    public ResponseEntity<?> deleteUserComment(@PathVariable Long id, @RequestBody Long operator) {
        commentService.deleteComment(id, operator);
        return ResponseEntity.ok("评论已删除");
    }

    @GetMapping("/course/{courseId}")
    public ResponseEntity<?> getCommentsByCourseId(@PathVariable Long courseId) {
        return ResponseEntity.ok(commentService.getCommentsByCourseId(courseId));
    }
}
